package com.example.springrestrepositories.controller;

import com.example.springrestrepositories.respository.PersonRepository;
import com.example.springrestrepositories.summary.PersonSummary;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PersonController {

    private final PersonRepository personRepository;

    public PersonController(PersonRepository personRepository) {
        this.personRepository = personRepository;
    }

    @GetMapping("/findByLastName")
    public List<PersonSummary> findByLastName(@RequestParam(value = "lastName") String lastName) {
        return personRepository.findByLastName(lastName);
    }
}